package drds.binlog.binlog_event;

import drds.binlog.binlog_event.event.FormatDescriptionLogEvent;
import drds.binlog.binlog_event.event.GtidLogEvent;
import drds.binlog.binlog_event.event.TableMapLogEvent;
import drds.binlog.common.Authors;
import drds.binlog.database_driver.packets.IGtidSet;
import drds.common.Author;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

/**
 * Log context will NOT write multi-threaded.
 */
@Author(name = Authors.LI_YANG)
public final class LogContext
{

    @Setter
    @Getter
    private final Map<Long, TableMapLogEvent> tableIdToTableMapLogEventMap = new HashMap<Long, TableMapLogEvent>();
    @Setter
    @Getter
    private FormatDescriptionLogEvent formatDescriptionLogEvent;
    @Setter
    @Getter
    private LogPosition logPosition;
    @Setter
    @Getter
    private IGtidSet gtidSet;
    @Setter
    @Getter
    private GtidLogEvent gtidLogEvent; // save current gtid log event

    public LogContext()
    {
        this.formatDescriptionLogEvent = FormatDescriptionLogEvent.format_description_event_5_x;
    }


    public final void putTableMapLogEvent(TableMapLogEvent tableMapLogEvent)
    {
        tableIdToTableMapLogEventMap.put(Long.valueOf(tableMapLogEvent.getTableId()), tableMapLogEvent);
    }

    public final TableMapLogEvent getTableMapLogEvent(final long tableId)
    {
        return tableIdToTableMapLogEventMap.get(Long.valueOf(tableId));
    }

    public final void clearTableIdToTableMapLogEventMap()
    {
        tableIdToTableMapLogEventMap.clear();
    }


}
